<template>
	<view>
		<view class="couponList">
			<view class="couponItem" v-for="(item,index) in couponList" :key="index">
				<image src="/static/img/active/coupon.png" class="itemBg" mode=""></image>
				<view class="itemInfo">
					<view class="value" v-if="item.value!='0.0'">{{item.value*10}}折</view>
					<view class="value" v-else>免单</view>
					<view class="infoOther">
						<view class="title">{{item.title}}</view>
						<view class="time">{{item.state=='1'?'使用时间':'有效期'}}：{{item.endtime}}</view>
						<view class="time">使用场馆：{{item.venue_name}}</view>
					</view>
					<view class="button no-use" v-if="formatDate(newDate)<item.endtime&&item.state=='0'"
						@click="navigatorPage">去使用
					</view>
					<view class="button use" v-if="formatDate(newDate)>item.endtime&&item.state=='0'">已过期</view>
					<view class="button use" v-if="item.state=='1'">已使用</view>
					<!-- <image src="/static/img/active/use.png" class="use" @click="navigatorPage"></image> -->
				</view>
			</view>
		</view>
		<view class="noData" v-if="couponList.length==0">
			<image src="@/static/img/common/nodata.png" class="image"></image>
			<view class="text">还没有获得优惠券哦～</view>
		</view>
	</view>
</template>

<script>
	import {
		getMyCouponList
	} from "@/api/active.js"
	export default {
		data() {
			return {
				couponList: [],
				newDate: new Date()
			}
		},
		onShow() {
			this.getMyCouponList()
		},
		methods: {
			formatDate(date) {
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1  
				const day = String(date.getDate()).padStart(2, '0');
				const hours = String(date.getHours()).padStart(2, '0');
				const minutes = String(date.getMinutes()).padStart(2, '0');
				const seconds = String(date.getSeconds()).padStart(2, '0');
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			},
			navigatorPage() {
				uni.switchTab({
					url: "/pages/index/index"
				})
			},
			getMyCouponList() {
				getMyCouponList().then(res => {
					this.couponList = res.data
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.noData {
		padding-top: 390rpx;
		margin: 0 auto;
		text-align: center;

		.image {
			width: 320rpx;
			height: 320rpx;
		}

		.text {
			font-size: 28rpx;
			color: #B0B0B0;
		}
	}

	.couponList {
		margin-top: 20rpx;
	}

	.couponItem {
		position: relative;
		height: 170rpx;
		margin: 0 28rpx 32rpx;

		.itemBg {
			position: absolute;
			width: 100%;
			height: 100%;
		}

		.itemInfo {
			position: relative;
			display: flex;
			align-items: center;
			justify-content: space-between;
			position: relative;
			z-index: 1;
			padding: 30rpx 16rpx;

			.value {
				width: 176rpx;
				text-align: center;
				font-size: 60rpx;
				color: #F13933;
				font-weight: 600;
				border-right: 2rpx dashed #F6DCD3;
			}

			.infoOther {
				flex: 1;
				margin-left: 32rpx;

				.title {
					font-size: 32rpx;
					color: #F13933;
					margin-bottom: 10rpx;
				}

				.time {
					font-size: 24rpx;
					color: #999999;
					margin-bottom: 10rpx;
				}
			}

			.button {
				width: 88rpx;
				height: 88rpx;
				font-size: 24rpx;
				text-align: center;
				color: #ffffff;
				line-height: 88rpx;
				border-radius: 50%;
				margin-right: 4rpx;
			}

			.use {
				background-color: #8d8d8d;
			}

			.no-use {
				background-color: #f13b34;
			}
		}

	}
</style>